package com.ruoyi.park.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.park.domain.MaHouseMaterial;
import com.ruoyi.park.service.IMaHouseMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 仓库物资Controller
 *
 * @author cjie
 * @date 2021-09-16
 */
@Api(tags = " 仓库物资")
@RestController
@RequestMapping("/maHouseMaterial")
public class MaHouseMaterialController extends BaseController {
    @Autowired
    private IMaHouseMaterialService maHouseMaterialService;

    /**
     * 查询仓库物资列表
     */
    @ApiOperation(value="查询仓库物资列表", notes="查询仓库物资列表")
    @PreAuthorize(hasPermi = "park:maHouseMaterial:list")
    @GetMapping("/list")
    public TableDataInfo list(MaHouseMaterial maHouseMaterial) {
        startPage();
        List<MaHouseMaterial> list = maHouseMaterialService.selectMaHouseMaterialList(maHouseMaterial);
        return getDataTable(list);
    }

    /**
     * 导出仓库物资列表
     */
    @ApiOperation(value="导出仓库物资列表", notes="导出仓库物资列表")
    @PreAuthorize(hasPermi = "park:maHouseMaterial:export")
    @Log(title = "仓库物资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaHouseMaterial maHouseMaterial) throws IOException {
        List<MaHouseMaterial> list = maHouseMaterialService.selectMaHouseMaterialList(maHouseMaterial);
        ExcelUtil<MaHouseMaterial> util = new ExcelUtil<MaHouseMaterial>(MaHouseMaterial.class);
        util.exportExcel(response, list, "仓库物资数据");
    }
    /**
     * 获取仓库物资详细信息
     */
    @ApiOperation(value="获取仓库物资详细信息", notes="获取仓库物资详细信息")
    @PreAuthorize(hasPermi = "park:maHouseMaterial:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(maHouseMaterialService.selectMaHouseMaterialById(id));
    }

    /**
     * 新增仓库物资
     */
    @ApiOperation(value="新增仓库物资", notes="新增仓库物资")
    @PreAuthorize(hasPermi = "park:maHouseMaterial:add")
    @Log(title = "仓库物资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaHouseMaterial maHouseMaterial) {
        return toAjax(maHouseMaterialService.insertMaHouseMaterial(maHouseMaterial));
    }

    /**
     * 修改仓库物资
     */
    @ApiOperation(value="修改仓库物资", notes="修改仓库物资")
    @PreAuthorize(hasPermi = "park:maHouseMaterial:edit")
    @Log(title = "仓库物资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaHouseMaterial maHouseMaterial) {
        return toAjax(maHouseMaterialService.updateMaHouseMaterial(maHouseMaterial));
    }

    /**
     * 删除仓库物资
     */
    @ApiOperation(value="删除仓库物资", notes="删除仓库物资")
    @ApiImplicitParam(name = "ids", value = "仓库物资ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "park:maHouseMaterial:remove")
    @Log(title = "仓库物资", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(maHouseMaterialService.deleteMaHouseMaterialByIds(ids));
    }
}
